//
//  main.cpp
//  EMT_V2_Crisis
//
//  Created by Duong Ngo on 6/5/17.
//  Copyright © 2017 Duong Ngo. All rights reserved.
//

#include <iostream>
#include "global.hpp"
#include "mapping.hpp"
#include "read_steady_state.hpp"
#include "foc_problem.hpp"
#include "homotopy.hpp"

int main()
{
    // Global mapping and vector showing position
    find_original_map(original_map);
    find_equation_map(eqn_map);
    find_positions_of_state_and_forward_variables(state_position, forward_position, var_role);

    // Read steady state
    std::vector<double> ss(var_foc);     //Steady State
    read_steady(ss);
    print_vector(ss);

    
    
    // Initial guess
    std::vector<double> x_init((T+1)*var_foc);
    initial_guess_as_steady_state(ss, x_init);
    
    // Starting state
    starting_state[0] = ss[original_map.at("s.n")];
    starting_state[1] = ss[original_map.at("s.m")];
    starting_state[2] = ss[original_map.at("s.bh")];
    starting_state[3] = ss[original_map.at("s.k")];
    starting_state[4] = ss[original_map.at("s.Rm")];
    starting_state[5] = ss[original_map.at("s.x")];
    starting_state[6] = ss[original_map.at("s.Rn")];
    
    // Exogenous shock
    std::vector<double> kappa_start(T+1), kappa_end(T+1);
    std::vector<double> x_start(T+1), x_end(T+1);
    std::vector<double> rn_start(T+1), rn_end(T+1);
    
    
    // CHOOSE mode to set up
    // mode = 0 - monetary policy without raising Rn
    // mode = 1 - monetary policy with raising Rn (only run after getting files from mode = 0
    int mode=1;
    
    
    if (mode==0){
        homotopy_from_ss_to_homo_kappa(ss, kappa_start, kappa_end, x_start, x_end, rn_start, rn_end, x_init);
        homotopy_from_homo_kappa_to_kappa(ss, kappa_start, kappa_end, x_start, x_end, rn_start, rn_end, x_init);
    }
    
    if (mode==1){
        int T_zero = 20; // After 20 periods, central bank raises Rn
        std::string fname2 ("//Users//duongngo//Documents//Research//E-Monetary Theory//Paper_and_code//EMT_V6//C code//Output//EMT_ms_rule_without_rn.txt");
        read_guess_from_previous_homotopy(fname2, x_init);
        homotopy_for_vec_rn(T_zero, ss, kappa_start, kappa_end, x_start, x_end, rn_start, rn_end, x_init);
    }




    
 
    return 0;
}
